package logic

import (
	"context"
	"goods-mgr/model"
	"goods-mgr/orderrpc/internal/svc"
	"goods-mgr/orderrpc/orderrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type OrderAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewOrderAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OrderAddLogic {
	return &OrderAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *OrderAddLogic) OrderAdd(in *orderrpc.OrderAddRequest) (*orderrpc.OrderAddResponse, error) {
	// todo: add your logic here and delete this line

	order := model.Order{
		Img:   in.Img,
		Name:  in.Name,
		Price: float64(in.Price),
		Num:   int64(int(in.Num)),
	}
	model.DB.Debug().Create(&order)
	return &orderrpc.OrderAddResponse{
		OrderId: int64(order.ID),
	}, nil
}
